﻿using System;
using System.Linq;
using Contracts.Entities;
using Contracts.Library;

namespace Definition.WebImport
{
    public class TmdbGetMovieRequest : TmdbRequest
    {
        public TmdbMovie Request(string id)
        {
            var xmlMovie = GetMoviesElement(id);
            var elements = xmlMovie.Elements();

            if (elements.Count() != 0)
            {
                return elements.FirstOrDefault().FromXElement<TmdbMovie>();
            }
            else
                throw new ArgumentNullException("elements.Count() == 0");
        }

        public override string GetUrl()
        {
            return String.Format("{0}{1}/{2}/{3}/", TmdbApi.Url, TmdbApi.Version, "Movie.getInfo/de/xml", TmdbApi.Key);
        }
    }
}
